# vim: set ft=python

def contains_any(string, substrings):
	contains = [string.find(substring) != -1 for substring in substrings]
	return reduce(lambda a, b: a or b, contains)

def build_posix():
	files = filter(lambda a: not contains_any(a, ['Win32', 'D3D10', 'PSP']), \
		map(str, Glob('*.cpp')))

	comp_flags = '-Wall -DGENBEN_PLATFORM_LINUX'
	dbg_env = Environment(CCFLAGS = comp_flags + ' -g -D_DEBUG')
	rel_env = Environment(CCFLAGS = comp_flags + ' -O3 -march=i686 -DNDEBUG')

	release = ARGUMENTS.get('release', 0)
	env = rel_env if release > 0 else dbg_env
	program = env.Program('genben', files, LIBS=['SDL', 'GL', 'GLU'])
	return str(program[0])

if str(Platform()) == 'posix':
	output = build_posix()
	Return('output')
